<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<script language="VBScript">
function FindProviders()
		Dim i, count
		Dim Enroll
		i = 0
		count=0
		Dim el
		Dim temp
		Dim selectprov
		selectprov = -1
		On Error Resume Next
		
		Set Enroll = EnrollNew
		if(0 = len(Enroll.enumProviders(0,0))) Then
			Set Enroll = EnrollOld
		end if
		
		Do While True
			temp = ""
			Enroll.providerType = 1
			temp = Enroll.enumProviders(i,0)
			If Len(temp) = 0 Then
				Exit Do
			Else
				If temp <> "Microsoft Base Cryptographic Provider v1.0" Then
					set el = document.createElement("OPTION")
					el.text = temp
					el.value = 1
					document.all.cryptprov.add(el)
					count = count + 1
					If selectprov = -1 Then
						If el.text = "Microsoft Enhanced Cryptographic Provider v1.0" Then
							selectprov = count
						End If
					End If
					If Left(el.text, 9) <> "Microsoft" Then
						selectprov = count
					End If
				End If
				i = i + 1
			End If
		Loop
		If selectprov = -1 Then
			selectprov = 0
		End If
		document.all.cryptprov.selectedIndex = selectprov
	End function	'FindProviders	

function OnSub
	Dim theForm
		Dim Enroll
		Dim pkcs10req
		Set theForm=Document.forms(0)
		On Error Resume Next
		
		Set Enroll = EnrollNew
		if(0 = len(Enroll.enumProviders(0,0))) Then
			Set Enroll = EnrollOld
		end if		
		

		set options = document.all.cryptProv.options
		index = options.selectedIndex
		Enroll.providerName = options(index).text
		Enroll.providerType = options(index).value
		Enroll.HashAlgorithm = "SHA1"
		cn="cn=" & theForm.refNo.value
		Enroll.KeySpec = 2
		Enroll.GenKeyFlags = 67108867
		pkcs10req=Enroll.CreatePKCS10(cn, "1.3.6.1.5.5.7.3.2")
		theForm.myKey.Value=pkcs10req

		if(pkcs10req=Empty) Then
			errorString="The error '" & hex(Err.Number) & "' occurred."& chr(13) & chr(10) & "Your certificate request could not be generated."
			err=MsgBox(errorString,0,"Internet Explorer Certificate Request")
			window.event.returnvalue=false
			OnSub=false
			on error goto 0
			exit function
		end if
		'Exit Sub
End function
</script>
<html>
	<head>
		<title></title>
		<link href="<%=request.getContextPath()%>/css/style.css"
			rel="stylesheet" type="text/css" media="all">
	<object
	classid="clsid:43F8F289-7A20-11D0-8F06-00C04FC295E1" id="EnrollOld" >
	</object>
	<object
	classid="clsid:127698e4-e730-4e5c-a2b1-21490a70c8a1" id="EnrollNew">
	</object>
	</head>
	<body leftmargin=0 topmargin=0 marginheight="0" marginwidth="0"
		background="images/bg_right.gif" onload="FindProviders()">
		<br />
		<table width="80%" border="0" cellpadding="0" cellspacing="0"
			align="center">
			<tr>
				<td>
					<table width="85%" align="center" cellpadding=5 cellspacing=0>
						<tr>
							<td align=center>
								<span class="alert"> ${msg} </span>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<form action="<%=request.getContextPath()%>/entUser/downloadEntUserCert.html" method="post">
						<table width="80%" border=0 align="center" cellpadding="3"
							cellspacing="1" bgcolor="#cccccc">
							<tr>
								<td width="15%" class=list01>
									企业名称
									<input type="hidden" name="ID" value="${entUserCert.ID}" />
								</td>
								<td width="35%" class=list02>
									${entUserCert.entname}
								</td>
								<td width="15%" class=list01>
									持有人姓名
								</td>
								<td width="35%" class=list02>
									${entUserCert.username}
								</td>
							</tr>
							<tr>
								<td width="15%" class=list01>
									证书申请方式
								</td>
								<td width="35%" class=list02>
									${requestType}
								</td>
								<td width="15%" class=list01>
									证书SN
								</td>
								<td width="35%" class=list02>
									${entUserCert.certSN}
								</td>
							</tr>
							<tr>
								<td width="20%" class=list01>
									证书类型
								</td>
								<td width="30%" class=list02>
									${certType}
								</td>
								<td width="20%" class=list01>
									USBKEYID
								</td>
								<td width="30%" class=list02>
									${entUserCert.usbkeyid}
								</td>
							</tr>
							<tr>
								<td width="15%" class=list01>
									CSP
								</td>
								<td width="35%" class=list02 colspan="4">
									<select id="cryptProv">
										<OPTION SELECTED VALUE="1">
											Microsoft Base Cryptographic Provider v1.0
									</select>
									<input type="hidden" name="myKey" />
									<input type="hidden" name="usertype" value="2" />
									<font color="red"> </font>
								</td>
							</tr>
							<tr>
								<td width="15%" class=list03 colspan="4">
									<input type="submit" value="代为下载证书" onclick="OnSub()" />
									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
									<input type="button" value="打印两码" />
								</td>
							</tr>
						</table>
					</form>
				</td>
			</tr>
		</table>
	</body>
</html>